use user_auth_rs::log_i;
use user_auth_rs::common::constants::UDID_LEN;
use user_auth_rs::entry::user_auth_ffi::{InitInputFfi, InitOutputFfi};
use user_auth_rs::commands::system_commands::{InitInput, InitOutput, DefaultInitCommandExecutor, InitCommandExecutor};
use std::mem;
use serde_json;
use user_auth_rs::ut_registry_guard;

#[test]
fn get_init_command_data() {
    // Note: Integration tests run with default registry implementations
    let init_input_data =  vec![31, 37, 33, 41, 35, 42, 44, 45, 41, 35, 37, 32, 38, 34, 33, 31, 41, 36, 33, 43, 46, 33, 30, 44, 46, 33, 32, 34, 30, 32, 45, 35, 39, 42, 32, 38, 36, 33, 46, 46, 41, 45, 43, 37, 34, 34, 31, 41, 31, 43, 33, 42, 39, 31, 35, 45, 42, 38, 33, 41, 45, 30, 38, 36];
    
    log_i!("InitInputFfi size: {} bytes", mem::size_of::<InitInputFfi>());
    log_i!("Test data length: {} bytes", init_input_data.len());
    
    // 类似 C 语言的 memcpy 操作
    let mut init_input_ffi = InitInputFfi::default();
    unsafe {
        std::ptr::copy_nonoverlapping(
            init_input_data.as_ptr(),
            &mut init_input_ffi.device_udid as *mut u8,
            mem::size_of::<InitInputFfi>()
        );
    }
    let init_input: InitInput = init_input_ffi;
    let json = serde_json::to_string(&init_input).unwrap();
    log_i!("{}", json);

    // 3. 反序列化回来验证
    let decoded: InitInput = serde_json::from_str(&json).unwrap();
    assert_eq!(init_input, decoded);
    
    // 让测试通过
    assert_eq!(1,1);
}

#[test]
fn test_init_command() {
    let _guard = ut_registry_guard!();
    const DEVICE_UDID: [u8; UDID_LEN] = [31, 37, 33, 41, 35, 42, 44, 45, 41, 35, 37, 32, 38, 34, 33, 31, 41, 36, 33, 43, 46, 33, 30, 44, 46, 33, 32, 34, 30, 32, 45, 35, 39, 42, 32, 38, 36, 33, 46, 46, 41, 45, 43, 37, 34, 34, 31, 41, 31, 43, 33, 42, 39, 31, 35, 45, 42, 38, 33, 41, 45, 30, 38, 36];

    let init_input = InitInput {
        device_udid: DEVICE_UDID,
    };
    let init_command_exector = Box::new(DefaultInitCommandExecutor);
    let _init_output: InitOutput = init_command_exector.execute(init_input).unwrap();
    assert_eq!(1,1);
}